package rbac.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import rbac.dao.PermissionDao;
import rbac.entity.RbacPermission;
import rbac.service.PermissionService;


/**
 * RBAC 权限管理 service 实现类.
 * 
 * @author Huadi
 * @author Zoufengyang
 */
@Service("permissionService")
public class PermissionServiceImpl implements PermissionService {

	@Autowired
	@Qualifier("permissionDao")
	private PermissionDao permissionDao;

	@Override
	public void delete(RbacPermission permission) {
		permissionDao.delete(permission);
	}

	@Override
	public RbacPermission getPermission(Integer id) {
		return permissionDao.getPermission(id);
	}

	@Override
	public void save(RbacPermission permission) {
		permissionDao.save(permission);
	}

	@Override
	public void update(RbacPermission permission) {
		permissionDao.update(permission);
	}

	@Override
	public void delete(Integer id) {
		permissionDao.delete(id);
	}

	@Override
	public String getPermissionContent(RbacPermission permission) {
		return permission.getResources();
	}

	@Override
	public List<String> getPermissionContentList(RbacPermission permission) {
		List<String> list = new ArrayList<String>();
		for (String string : permission.extractResources()) {
			list.add(string);
		}

		return list;
	}

	@Override
	public List<RbacPermission> getAllPermissions() {
		return permissionDao.getAllPermissions();
	}

}
